package com.huawei.hms.support.api.push.b.b;

import android.text.TextUtils;
import com.huawei.hms.support.api.entity.pay.HwPayConstant;
import com.huawei.hms.support.api.push.b.c.b;
import com.huawei.hms.support.log.HMSLog;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class a implements Serializable {
    private String A;
    private String B;
    private String C;
    private String D;
    private String E = "";
    private int F = 1;
    private int G = 0;
    private String H;
    private String I;
    private String J;
    private int K = b.STYLE_1.ordinal();
    private int L = 0;
    private String[] M = null;
    private String[] N = null;
    private String[] O = null;
    private int P = 0;
    private String[] Q = null;
    private String R = "";
    private String S = "";
    public int a = 1;
    public String b = "";
    private String c = "";
    private String d;
    private String e;
    private String f;
    private String g;
    private int h;
    private String i;
    private int j;
    private String k;
    private int l;
    private int m;
    private String n;
    private String o = "";
    private String p = "";
    private String q;
    private String r = "";
    private String s = "";
    private String t = "";
    private String u = "";
    private String v;
    private String w;
    private String x;
    private String y;
    private String z;

    public a(byte[] bArr, byte[] bArr2) {
        try {
            this.I = new String(bArr, "UTF-8");
            this.J = new String(bArr2, "UTF-8");
        } catch (Exception e) {
            HMSLog.e("PushSelfShowLog", "get msg byte arr error");
        }
    }

    public String a() {
        HMSLog.d("PushSelfShowLog", "msgId =" + this.o);
        return this.o;
    }

    public boolean b() {
        int i = 1;
        boolean z = false;
        try {
            if (TextUtils.isEmpty(this.J)) {
                HMSLog.d("PushSelfShowLog", "token is null");
            } else {
                this.k = this.J;
                if (TextUtils.isEmpty(this.I)) {
                    HMSLog.d("PushSelfShowLog", "msg is null");
                } else {
                    JSONObject jSONObject = new JSONObject(this.I);
                    this.j = jSONObject.getInt("msgType");
                    if (this.j != 1) {
                        HMSLog.d("PushSelfShowLog", "not a selefShowMsg");
                    } else {
                        a(jSONObject);
                        JSONObject jSONObject2 = jSONObject.getJSONObject("msgContent");
                        if (jSONObject2 == null) {
                            HMSLog.i("PushSelfShowLog", "msgObj == null");
                        } else if (b(jSONObject2)) {
                            if (jSONObject2.has("dispPkgName")) {
                                this.p = jSONObject2.getString("dispPkgName");
                            }
                            this.m = jSONObject2.has("rtn") ? jSONObject2.getInt("rtn") : 1;
                            if (jSONObject2.has("fm")) {
                                i = jSONObject2.getInt("fm");
                            }
                            this.l = i;
                            c(jSONObject2);
                            if (jSONObject2.has("extras")) {
                                this.q = jSONObject2.getJSONArray("extras").toString();
                            }
                            z = d(jSONObject2);
                        }
                    }
                }
            }
        } catch (JSONException e) {
            HMSLog.d("PushSelfShowLog", "parse message exception.");
        } catch (Exception e2) {
            HMSLog.d("PushSelfShowLog", e2.toString());
        }
        return z;
    }

    private void a(JSONObject jSONObject) throws JSONException {
        if (jSONObject.has("group")) {
            this.c = jSONObject.getString("group");
            HMSLog.d("PushSelfShowLog", "NOTIFY_GROUP:" + this.c);
        }
        if (jSONObject.has("badgeClass")) {
            this.b = jSONObject.getString("badgeClass");
            HMSLog.d("PushSelfShowLog", "BADGE_CLASS:" + this.b);
        }
        if (jSONObject.has("badgeAddNum")) {
            this.a = jSONObject.getInt("badgeAddNum");
            HMSLog.d("PushSelfShowLog", "BADGE_ADD_NUM:" + this.a);
        }
    }

    private boolean b(JSONObject jSONObject) throws JSONException {
        if (jSONObject.has("msgId")) {
            Object obj = jSONObject.get("msgId");
            if (obj instanceof String) {
                this.o = (String) obj;
            } else if (obj instanceof Integer) {
                this.o = String.valueOf(((Integer) obj).intValue());
            }
            return true;
        }
        HMSLog.i("PushSelfShowLog", "msgId == null");
        return false;
    }

    private void c(JSONObject jSONObject) throws JSONException {
        int i = 0;
        if (jSONObject.has("ap")) {
            String string = jSONObject.getString("ap");
            StringBuilder stringBuilder = new StringBuilder();
            if (TextUtils.isEmpty(string) || string.length() >= 48) {
                this.n = string.substring(0, 48);
                return;
            }
            int length = 48 - string.length();
            while (i < length) {
                stringBuilder.append("0");
                i++;
            }
            stringBuilder.append(string);
            this.n = stringBuilder.toString();
        }
    }

    private boolean d(JSONObject jSONObject) throws JSONException {
        if (!jSONObject.has("psContent")) {
            return false;
        }
        JSONObject jSONObject2 = jSONObject.getJSONObject("psContent");
        if (jSONObject2 == null) {
            return false;
        }
        this.r = jSONObject2.getString("cmd");
        if (jSONObject2.has("content")) {
            this.s = jSONObject2.getString("content");
        } else {
            this.s = "";
        }
        if (jSONObject2.has("notifyIcon")) {
            this.t = jSONObject2.getString("notifyIcon");
        } else {
            this.t = "" + this.o;
        }
        if (jSONObject2.has("statusIcon")) {
            this.v = jSONObject2.getString("statusIcon");
        }
        if (jSONObject2.has("notifyTitle")) {
            this.u = jSONObject2.getString("notifyTitle");
        }
        if (jSONObject2.has("notifyParam")) {
            i(jSONObject2);
        }
        if (jSONObject2.has("param")) {
            return e(jSONObject2);
        }
        return false;
    }

    private boolean e(JSONObject jSONObject) {
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject("param");
            if (jSONObject2.has("autoClear")) {
                this.h = jSONObject2.getInt("autoClear");
            } else {
                this.h = 0;
            }
            if ("app".equals(this.r) || "cosa".equals(this.r)) {
                f(jSONObject2);
            } else if ("phone".equals(this.r)) {
                if (jSONObject2.has("phoneNum")) {
                    this.y = jSONObject2.getString("phoneNum");
                } else {
                    HMSLog.d("PushSelfShowLog", "phoneNum is null");
                    return false;
                }
            } else if ("url".equals(this.r)) {
                g(jSONObject2);
            } else if ("rp".equals(this.r)) {
                h(jSONObject2);
            }
            return true;
        } catch (Throwable e) {
            HMSLog.e("PushSelfShowLog", "ParseParam error ", e);
            return false;
        }
    }

    private boolean f(JSONObject jSONObject) throws JSONException {
        if (jSONObject == null) {
            return false;
        }
        if (jSONObject.has("acn")) {
            this.A = jSONObject.getString("acn");
            this.i = this.A;
        }
        if (jSONObject.has("intentUri")) {
            this.i = jSONObject.getString("intentUri");
        }
        if (jSONObject.has("appPackageName")) {
            this.z = jSONObject.getString("appPackageName");
            return true;
        }
        HMSLog.d("PushSelfShowLog", "appPackageName is null");
        return false;
    }

    private boolean g(JSONObject jSONObject) throws JSONException {
        if (jSONObject == null) {
            return false;
        }
        if (jSONObject.has("url")) {
            this.B = jSONObject.getString("url");
            if (jSONObject.has("inBrowser")) {
                this.F = jSONObject.getInt("inBrowser");
            }
            if (jSONObject.has("needUserId")) {
                this.G = jSONObject.getInt("needUserId");
            }
            if (jSONObject.has(HwPayConstant.KEY_SIGN)) {
                this.H = jSONObject.getString(HwPayConstant.KEY_SIGN);
            }
            if (jSONObject.has("rpt") && jSONObject.has("rpl")) {
                this.C = jSONObject.getString("rpl");
                this.D = jSONObject.getString("rpt");
                if (jSONObject.has("rpct")) {
                    this.E = jSONObject.getString("rpct");
                }
            }
            return true;
        }
        HMSLog.d("PushSelfShowLog", "url is null");
        return false;
    }

    private boolean h(JSONObject jSONObject) throws JSONException {
        if (jSONObject == null) {
            return false;
        }
        if (jSONObject.has("rpt") && jSONObject.has("rpl")) {
            this.C = jSONObject.getString("rpl");
            this.D = jSONObject.getString("rpt");
            if (jSONObject.has("rpct")) {
                this.E = jSONObject.getString("rpct");
            }
            if (jSONObject.has("needUserId")) {
                this.G = jSONObject.getInt("needUserId");
            }
            return true;
        }
        HMSLog.d("PushSelfShowLog", "rpl or rpt is null");
        return false;
    }

    public byte[] c() {
        try {
            String str = "";
            JSONObject jSONObject = new JSONObject();
            JSONObject jSONObject2 = new JSONObject();
            JSONObject jSONObject3 = new JSONObject();
            JSONObject jSONObject4 = new JSONObject();
            jSONObject4.put("autoClear", this.h);
            jSONObject4.put("s", this.d);
            jSONObject4.put("r", this.e);
            jSONObject4.put("smsC", this.f);
            jSONObject4.put("mmsUrl", this.g);
            jSONObject4.put("url", this.B);
            jSONObject4.put("inBrowser", this.F);
            jSONObject4.put("needUserId", this.G);
            jSONObject4.put(HwPayConstant.KEY_SIGN, this.H);
            jSONObject4.put("rpl", this.C);
            jSONObject4.put("rpt", this.D);
            jSONObject4.put("rpct", this.E);
            jSONObject4.put("appPackageName", this.z);
            jSONObject4.put("acn", this.A);
            jSONObject4.put("intentUri", this.i);
            jSONObject4.put("phoneNum", this.y);
            jSONObject4.put("replyToSms", this.x);
            jSONObject4.put("smsNum", this.w);
            jSONObject3.put("cmd", this.r);
            jSONObject3.put("content", this.s);
            jSONObject3.put("notifyIcon", this.t);
            jSONObject3.put("notifyTitle", this.u);
            jSONObject3.put("statusIcon", this.v);
            jSONObject3.put("param", jSONObject4);
            jSONObject2.put("dispPkgName", this.p);
            jSONObject2.put("msgId", this.o);
            jSONObject2.put("fm", this.l);
            jSONObject2.put("ap", this.n);
            jSONObject2.put("rtn", this.m);
            jSONObject2.put("psContent", jSONObject3);
            if (this.q != null && this.q.length() > 0) {
                jSONObject2.put("extras", new JSONArray(this.q));
            }
            jSONObject.put("msgType", this.j);
            jSONObject.put("msgContent", jSONObject2);
            jSONObject.put("group", this.c);
            jSONObject.put("badgeClass", this.b);
            jSONObject.put("badgeAddNum", this.a);
            return jSONObject.toString().getBytes("UTF-8");
        } catch (JSONException e) {
            HMSLog.e("PushSelfShowLog", "getMsgData failed JSONException");
            return new byte[0];
        } catch (UnsupportedEncodingException e2) {
            HMSLog.e("PushSelfShowLog", "getMsgData failed UnsupportedEncodingException");
            return new byte[0];
        }
    }

    public byte[] d() {
        try {
            if (this.k != null && this.k.length() > 0) {
                return this.k.getBytes("UTF-8");
            }
        } catch (Exception e) {
            HMSLog.w("PushSelfShowLog", "getToken getByte failed ");
        }
        return new byte[0];
    }

    private boolean i(JSONObject jSONObject) {
        HMSLog.d("PushSelfShowLog", "enter parseNotifyParam");
        try {
            JSONObject jSONObject2 = jSONObject.getJSONObject("notifyParam");
            if (!jSONObject2.has("style")) {
                return false;
            }
            k(jSONObject2);
            j(jSONObject2);
            return true;
        } catch (JSONException e) {
            HMSLog.i("PushSelfShowLog", e.toString());
            return false;
        }
    }

    private void j(JSONObject jSONObject) throws JSONException {
        this.K = jSONObject.getInt("style");
        HMSLog.d("PushSelfShowLog", "style:" + this.K);
        b bVar = b.STYLE_1;
        if (this.K >= 0 && this.K < b.values().length) {
            bVar = b.values()[this.K];
        }
        switch (b.a[bVar.ordinal()]) {
            case 1:
                if (jSONObject.has("iconCount")) {
                    this.P = jSONObject.getInt("iconCount");
                }
                if (this.P > 0) {
                    if (this.P > 6) {
                        this.P = 6;
                    }
                    HMSLog.d("PushSelfShowLog", "iconCount:" + this.P);
                    this.Q = new String[this.P];
                    for (int i = 0; i < this.P; i++) {
                        String str = "icon" + (i + 1);
                        if (jSONObject.has(str)) {
                            this.Q[i] = jSONObject.getString(str);
                        }
                    }
                    return;
                }
                return;
            case 2:
                if (jSONObject.has("subTitle")) {
                    this.R = jSONObject.getString("subTitle");
                    HMSLog.d("PushSelfShowLog", "subTitle:" + this.R);
                    return;
                }
                return;
            case 3:
            case 4:
                if (jSONObject.has("bigPic")) {
                    this.S = jSONObject.getString("bigPic");
                    HMSLog.d("PushSelfShowLog", "bigPicUrl:" + this.S);
                    return;
                }
                return;
            default:
                return;
        }
    }

    private void k(JSONObject jSONObject) throws JSONException {
        if (jSONObject.has("btnCount")) {
            this.L = jSONObject.getInt("btnCount");
        }
        if (this.L > 0) {
            if (this.L > 3) {
                this.L = 3;
            }
            HMSLog.d("PushSelfShowLog", "btnCount:" + this.L);
            this.M = new String[this.L];
            this.N = new String[this.L];
            this.O = new String[this.L];
            for (int i = 0; i < this.L; i++) {
                String str = "btn" + (i + 1) + "Text";
                String str2 = "btn" + (i + 1) + "Image";
                String str3 = "btn" + (i + 1) + "Event";
                if (jSONObject.has(str)) {
                    this.M[i] = jSONObject.getString(str);
                }
                if (jSONObject.has(str2)) {
                    this.N[i] = jSONObject.getString(str2);
                }
                if (jSONObject.has(str3)) {
                    this.O[i] = jSONObject.getString(str3);
                }
            }
        }
    }

    public String e() {
        return this.c;
    }

    public int f() {
        return this.h;
    }

    public String g() {
        return this.i;
    }

    public String h() {
        return this.n;
    }

    public String i() {
        return this.p;
    }

    public String j() {
        return this.r;
    }

    public String k() {
        return this.s;
    }

    public String l() {
        return this.t;
    }

    public String m() {
        return this.u;
    }

    public String n() {
        return this.y;
    }

    public String o() {
        return this.z;
    }

    public String p() {
        return this.A;
    }
}
